<?php 
require "DataLoad.php"; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php CheckAdmin2();?>
<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>
<style type="text/css" media="all">

</style>
<script language="javascript">
var TempArr=[];//存贮option

function Init() {
var SelectObj=document.eventadd.elements["demo"]
/*先将数据存入数组*/
with(SelectObj)
	for(i=0;i<length;i++)TempArr[i]=[options[i].text,options[i].value]
}

function SelectTip(flag) {
var TxtObj=document.eventadd.elements["tempinput"]
var SelectObj=document.getElementById("demo")
var Arr=[]
with(SelectObj) {
	var SelectHTML=innerHTML.match(/<[^>]*>/)[0]
	for(i=0;i<TempArr.length;i++)
	if(TempArr[i][0].indexOf(TxtObj.value)>-1||flag)//若找到以txt的内容开头的，添option。若flag为true,对下拉框初始化
	Arr[Arr.length]="<option value='"+TempArr[i][1]+"'>"+TempArr[i][0]+"</option>"
	innerHTML=SelectHTML+Arr.join()+"</SELECT>"
}
}
</script>

</head>

<body onload="Init()">

<div class="header">
<?php require "menu.php"; ?>
</div>
<div class="main">
			<?php 

switch (${"action"}) {
	case "del":
eventdel(${"id"});
getCueInfo("调分记录".${"id"}."已被删除");
		break;
	case "end":
eventEnd(${"id"});
getCueInfo("调分已归档");
		break;
	case "ends":
eventEnds(${"count"});
getCueInfo("约20条调分记录已被归档,可以点击相应角色查看");
		break;
} 
?>
			
	<div class="sideframe">
			<?php 
switch (${"action"}) {
	case "add":
SE_ADD();
		break;
	case "edit":
SpecEvent_editFrom(${"id"});
		break;
	default:

SpecEvent_addFrom();
		break;
} 
?>
	</div>
	<div class="rightframe">
		<?php 
SpecEvent_list("");
?>
	</div>
</div>
<?php require "footer.php"; ?>
<script language="javascript">
	$("textarea[name=object]").focus(
		function () {
			$("div.playerselectlayer").show()
		}
	);
	$("div.playerselectlayer .close").click(
		function () {
			$("div.playerselectlayer").hide()
		}
	);
	$("input[name=event_dkp]").focus(
		function () {
			$("div.playerselectlayer").hide()
		}
	);

</script>
</body>
</html>
<?php 
function playerselect($target) {
	extract($GLOBALS);

	$function_ret=$playerselect."<input type='text' name='tempinput' value='' size='16' onkeyup='SelectTip(0)'/><br><span id=\"demo\"><select name='demo' style='width:120px' size='10' onchange=\"object.value=object.value+'|'+options[selectedIndex].text;\">";
	$sql="Select * from player order by player_name";
	mysql_query($result2);
	for ($i=1; $i<=$result2->recordcount; $i=$i+1) {
		$function_ret=$playerselect."<option value='".$result2["player_name"]."'>".$result2["player_name"]."</option>";
		$result2->movenext;

	}

	$result2->close;
	$function_ret=$playerselect."</select></span>";
	return $function_ret;
} 

function SpecEvent_addFrom() {
	extract($GLOBALS);

	$sdate=time();
//特殊事件添加表单
//马甲替身, 仓库购买, 纪律奖惩, DKP转让, 其它
	print "<form name='eventadd' action='admin_eventadd.php?action=add' method='post'>";
	print "<table class='short outframe interlace'>";
	print "<tr><th>新建调分</th></tr>";
	print "<tr><td><div class='playerselectlayer outframe'><a href='javascript:void(0)' class='close'>X</a>".playerselect(1)."</div><textarea name='object' rows='5' cols='31'></textarea></td></tr>";
	print "<tr><td>分数 ".formselect("raid_class","id","class_name"," ")." <input type='text' name='event_dkp' value='' size='6'/></td></tr>";
	print "<tr><td>原因 ".speceventclass("")." <input type='' name='object2' value=''  size='10'/></td></tr>";
	print "<tr><td>日期 <input type='text' name='event_date' size='14' value='".strftime("%m/%d/%Y %H:%M:%S %p")."' /><input type='hidden' name='event_time' value='' /></td></tr>";
	print "<tr><td><input type='submit' value='确定'/><input type='hidden' name='postid' value='0' /></td></tr>";
	print "</table>";
	print "</form>";
	return $function_ret;
} 


function SpecEvent_editFrom($id) {
	extract($GLOBALS);

	if (!is_numeric($id)) {
		return $function_ret;

	} 
	$sdate=time();
//特殊事件添加表单
//马甲替身, 仓库购买, 纪律奖惩, DKP转让, 其它
	$sql="select * from raid_event where id=".$id;
	$result = mysql_query($sql);
	if ($result->bof || $result->eof) {

	}
		else
	{

		print "<form name='eventadd' action='admin_eventadd.php?action=edit' method='post'>";
		print "<table class='short outframe interlace'>";
		print "<tr><th>修改已有调分</th></tr>";
		print "<tr><td><div class='playerselectlayer outframe'><a href='javascript:void(0)' class='close'>X</a>".playerselect(1)."</div><textarea name='object' rows='5' cols='31'>".$result["event_object"]."</textarea></td></tr>";
		print "<tr><td>分数 ".formselect("raid_class","id","class_name",($result["raid_class"]))." <input type='text' name='event_dkp' value='".$result["event_dkp"]."' size='6'/></td></tr>";
		print "<tr><td>原因 ".speceventclass($result["event_class"])." <input type='' name='object2' value='".$result["event_object2"]."'  size='10'/></td></tr>";
		print "<tr><td>日期 <input type='text' name='event_date' size='14' value='".$result["event_time"]."' /><input type='hidden' name='event_time' value='' /></td></tr>";
		print " <td><input type='submit' value='编辑'/> <a href='admin_SpecEvent.php'>取消</a><input type='hidden' name='postid' value='".$result["id"]."' /><input type='hidden' name='rid' value='0' /></td></tr>";
		print "</table>";
		print "</form>";
	} 

	$result->close;
	return $function_ret;
} 

function SpecEvent_list($sstr) {
	extract($GLOBALS);

//特殊事件列表
	switch ($sstr) {
		case "":
			$sctstr="";
			break;
		case "":
			$sctstr="";
			break;
		case "":
			$sctstr="";
			break;
		case "":
			$sctstr="";
			break;
		case "":
			$sctstr="";
			break;
		default:

			$sctstr="";
			break;
	} 

	$sql="select * from raid_event where event_raidid=0 ".$sctstr." order by id desc ,event_time desc";
	$result = mysql_query($sql);

	print "<table class='interlace outframe hasfocus'>";
	print "<tr><th colspan='7'><div class='title'><img src='images/icon/note1.jpg' width='64' height='64' border=0 alt=''>调分事件列表 ".$result->recordcount."条</div><div class='filter'><a href='?action=ends&count=20' class='abtn3'>归档最早的20条</a></div></th></tr>";
	print "<tr class='coltitle'><td>时间</td><td>类型</td><td>事件人物 </td><td>解释</td><td>DKP</td><td>分类</td><td>操作</td></tr>";

	if ($result->bof || $result->eof) {

		print "<tr><td colspan='7'>None.</td></tr>";
	}
		else
	{

		for ($i=1; $i<=$result->recordcount; $i=$i+1) {
			print "<tr><td>".$result["event_time"]."</td><td>".$result["event_class"]."</td><td>".$result["event_object"]."</td><td>".$result["event_object2"]."</td><td>".$result["event_dkp"]."</td><td>".raidclassText($result["raid_class"])."</td><td><a href='?action=edit&id=".$result["id"]."' class='abtn'>编辑</a> <a href='?action=del&id=".$result["id"]."' class='abtn4'>删除</a> ";
			if ($_SEESION('level')<2) {
				print "<a href='?action=end&id=".$result["id"]."' class='abtn3'>归档</a>";
			} 
			print "</td></tr>";
			$result->movenext;

		}

	} 

	$result->close;
	print "</table>";
	return $function_ret;
} 


function SE_ADD() {
	extract($GLOBALS);

//特殊事件添加SQL
	return $function_ret;
} 

function eventdel($id) {
	extract($GLOBALS);

	if (!is_numeric(${"postid"})) {
		return $function_ret;

	} 
	$sql="delete 1 from raid_event where id=".$id;
	$conn->execute($sql);
//Response.redirect Url
	return $function_ret;
} 



function eventEnd($id) {
	extract($GLOBALS);

	$sid=$id;
//读事件
	$sql="select * from raid_event where id=".$sid." order by event_time desc";
	$result = mysql_query($sql);
	if ($result->bof || $result->eof) {

		$result->close;
		print "事件ID错误";
		return $function_ret;

	}
		else
	{

		$ename=$result["event_object"];
		$etime=$result["event_time"];
		$eDKP=$result["event_dkp"];
		$eNote=$result["event_object2"];
		$eDKPClass=$result["raid_class"];
		$eClass=$result["event_class"];
		$result->close;

		if ((strpos($ename,"|") ? strpos($ename,"|")+1 : 0)) {

			$ename=substr($ename,1,strlen($ename)-2);
			print $ename;
			$ename=explode("|",$ename);
		}
			else
		{

			$ename=array($ename);
		} 


//写
		for ($i=0; $i<=count($ename); $i=$i+1) {
			$sql="select * from player where player_name='".$ename[$i]."'";
			$result = mysql_query($sql);
			if ($result->bof || $result->eof) {

				print "找不到成员:".$ename[$i]." ";
			}
				else
			{

				$Conn->execute("update player_dkp set player_dkp=player_dkp+".$eDKP." , player_Basedkp=player_Basedkp+".$eDKP." where player_name='".$ename[$i]."' and raid_class=".$eDKPClass);
				$result["player_log"]=$result["player_log"]."<li>".$etime." 分类:".raidclassText($eDKPClass)." 调分:".$eDKP." 事由:".$eNote."</li>";
				$result->update;
			} 

			$result->close;

		}


//删
		eventdel($sid);
//Response.redirect Url
	} 

	return $function_ret;
} 




function eventEnds($count) {
	extract($GLOBALS);

//读事件
	for ($k=1; $k<=$count; $k=$k+1) {
		$sql="select * from raid_event where event_raidid=0 order by event_time";
		$result = mysql_query($sql);
		if ($result->bof || $result->eof) {

			$result->close;
			print "没有记录可被归档";
			return $function_ret;

		}
			else
		{

			$eid=$result["id"];
			$ename=$result["event_object"];
			$etime=$result["event_time"];
			$eDKP=$result["event_dkp"];
			$eNote=$result["event_object2"];
			$eDKPClass=$result["raid_class"];
			$eClass=$result["event_class"];
			$result->close;

			if ((strpos($ename,"|") ? strpos($ename,"|")+1 : 0)) {

				$ename=substr($ename,1,strlen($ename)-2);
				print $ename;
				$ename=explode("|",$ename);
			}
				else
			{

				$ename=array($ename);
			} 


//写
			for ($i=0; $i<=count($ename); $i=$i+1) {
				$sql="select * from player where player_name='".$ename[$i]."'";
				$result = mysql_query($sql);
				if ($result->bof || $result->eof) {

				  print "找不到成员:".$ename[$i]." ";
				}
				  else
				{

				  $Conn->execute("update player_dkp set player_dkp=player_dkp+".$eDKP." , player_Basedkp=player_Basedkp+".$eDKP." where player_name='".$ename[$i]."' and raid_class=".$eDKPClass);
				  $result["player_log"]=$result["player_log"]."<li>".$etime." 分类:".raidclassText($eDKPClass)." 调分:".$eDKP." 事由:".$eNote."</li>";
				  $result->update;
				} 

				$result->close;

			}

//删
			eventdel(intval($eid));
		} 


	}

//Response.redirect Url
	return $function_ret;
} 
?>
